import {fromJS} from 'immutable'
import {actionType} from './index'
import {formatTime} from "@/tool/Util";

const defaultState = fromJS({
    currTime: '',
    weatherPicUrl: '',
    weatherInfo: ''
})

const getCurrTime = () => {
    return formatTime(new Date())
}

export default (state = defaultState, action) => {
    switch (action.type) {
        case actionType.GET_CURR_TIME:
            return state.set('currTime', getCurrTime())
        case actionType.CHANGE_WEATHER:
            console.log('action:',action)
            return state.merge({
                weatherPicUrl: action.weatherPicUrl,
                weatherInfo: action.weatherInfo
            })
    }
    return state
}